package com.ghd.dataviz.config;

import com.corundumstudio.socketio.SocketIOServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * @author ：ghd
 * @date ：Created in 2020-03-18 23:34
 * @description：
 * @modified By：
 * @version: $
 */
@Slf4j
@Component
@Order(1)
public class ServerRunner implements CommandLineRunner {
    private final SocketIOServer server;

    @Autowired
    public ServerRunner(SocketIOServer server) {
        this.server = server;
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("ServerRunner 开始启动啦...");
        server.start();
    }

    @PreDestroy
    private void destroy() {
        server.stop();
    }
}
